<?php
header('content-type:text/html;charset=utf-8');	
	ini_set('date.timezone','Asia/Shanghai');
	
	//require_once $_SITE_PATH_ . "m/m_information.php";
	//require_once $_SITE_PATH_ . "m/m_tasklist.php";
	require_once 'Queue_Class.php';
	require_once 'UpFile_ApiClient.class.php';
	
	//$datacode=isset($_POST['code'])?$_POST['code']:'';
	
	//$m_information=new m_information();
	//$m_tasklist=new m_tasklist();
	$queue=new QueueClass();
	
	//$m_tasklist->_ssql='select `id`,`product_id` from tasklist where ts_type="1" and excuflag="0" and ts_flag="0" and `id`=108 order by `id` ';//asc limit 0,1 
	//$product_id=$m_tasklist->getArray($m_tasklist->query());
	//$count=$m_tasklist->getCount(' ts_type="1" and excuflag="0" and ts_flag="0" ');
	$api=new UpFile_ApiClient();
	$auth='fileflag_productid';
	$data=array('code'=>'','order_sn'=>'','taskid'=>'','apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
	$url='http://localhost/index.php?a=apis.FileFlag_productid';
	//重新用计划任务执行指定次数的推送数据任务。
	$result=$api->DoRequest($url,$auth,$data);
	var_dump($result);
	//$result=trim($result,'"');
	//echo $result;
	//echo '<br/>';
	//var_dump(json_decode(json_decode(trim($result,chr(231).chr(187).chr(191)),true)));
	$result=json_decode(trim($result,chr(231).chr(187).chr(191)),true);
	var_dump(json_decode($result));
	//echo $result;
	exit;
	
	$datacode=explode(',',$result);
	$code='';
	$code_str='';
	
	if(!empty($data[0]))
		{
			echo '<br/>'.$data[0];
		}
		else
			{
				exit;
			}
	
	if($count<=0)
		{
			exit;
		}
		else
			{
				for($i=0;$i<$count;$i++)
					{
						$code=json_decode(trim($product_id[$i]->product_id,chr(231).chr(187).chr(191)),true);//解压JSON数据
						$order_sn='';
						for($j=0;$j<count($code);$j++)
							{
								$code_str.=','.$code[$i]['code'];
								$order_sn=$code[$i]['order_sn'];
							}
						$code_str=trim($code_str,',');
						$product_id[$i]->code=$code_str;
						$product_id[$i]->order_sn=$order_sn;
						
						$queue->add_item($product_id[$i]->code);
					}
					/* var_dump($product_id);
				exit; */
				for($i=0;$i<$count;$i++)
					{
						$code=$queue->del_item();
						$auth='fileflag_task';
						$data=array('code'=>$code,'order_sn'=>$product_id[$i]->order_sn,'taskid'=>$product_id[$i]->id,'apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
						$url='http://localhost/index.php?a=apis.FileFlag_Client';
						//重新用计划任务执行指定次数的推送数据任务。
						//$result=$api->DoRequest($url,$auth,$data);
						usleep(100);
						 
					}
			}
			exit;





?>